package stackandqueue.stack.sequentialstack;

import stackandqueue.stack.inter.Stack;

public class SqStack<T> implements Stack<T> {

    private T[] arr;
    private int maxSize = 512;
    private int top = -1;

    public SqStack() {
        arr = (T[]) new Object[maxSize];
    }

    @Override
    public void clearStack() {
        top = -1;
    }

    @Override
    public boolean stackEmpty() {
        return top == -1;
    }

    @Override
    public T getTop() {
        if (top == -1) {
            return null;
        }
        return arr[top];
    }

    @Override
    public void push(T e) {
        if (top == maxSize - 1) {
            return;
        }
        arr[++top] = e;
    }

    @Override
    public T pop() {
        if (top == -1) {
            return null;
        }
        return arr[top--];
    }

    @Override
    public int stackLength() {
        return (top + 1);
    }
}
